package cj.web.marry.utils;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImagePic {
	
    public static void mergeImage(String path,File file1, File file2,String content,String fileName) throws IOException {        
        BufferedImage image1 = ImageIO.read(file1);  
        BufferedImage image2 = ImageIO.read(file2);  
  
        BufferedImage combined = new BufferedImage(image1.getWidth(), image1.getHeight(), BufferedImage.TYPE_INT_RGB);  
  
        // paint both images, preserving the alpha channels  
        Graphics g = combined.getGraphics();  
        g.drawImage(image1, 0, 0, null);  
        
        int w = 721;
		int h = 840;
        
        g.drawImage(image2, 30, 500, w, h, null);  
           
        g.setFont(new Font("Microsoft YaHei", Font.BOLD, 40));
        g.setColor(Color.RED);
        g.drawString(content, 290, 470);
        g.dispose();          
        // Save as new image  
        ImageIO.write(combined, "JPG", new File(path, fileName));  
        
    }  
    
    public static void main(String[] args) throws IOException { 
    	String content = "甘宇翔 测试今日结婚";
    	String path = "C:\\"; 
    	String fileName ="3.jpg";
        File file1 = new File(path, "template.jpg");  
        File file2 = new File(path, "bb3.JPG");  
        mergeImage(path,file1, file2,content,fileName);  
    }  
}